package io.zcoder.innoway.fragments;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import butterknife.BindView;
import butterknife.ButterKnife;
import io.zcoder.innoway.R;
import io.zcoder.innoway.commons.Constants;
import io.zcoder.innoway.models.Dashboard;
import io.zcoder.innoway.widgets.TextViewCustom;

public class EntryOtherFragment extends Fragment {

    @BindView(R.id.entry_img)
    ImageView mEntryImg;
    @BindView(R.id.line_entry)
    View mLine;
    @BindView(R.id.entry_text)
    TextViewCustom mText;
    @BindView(R.id.entry_percent)
    TextViewCustom mPercentText;
    @BindView(R.id.your_s)
    TextViewCustom mYourText;

    private Dashboard mDashboard;
    private int mIndex;
    private String[] mDescreption;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.layout_entry_other_fragment, container, false);
        ButterKnife.bind(this, view);
        Bundle bundle = getArguments();
        mIndex = bundle.getInt(Constants.INDEX_EXTRAS);
        mDashboard = bundle.getParcelable(Constants.DASHBOARD_EXTRAS);
        mDescreption = getResources().getStringArray(R.array.entry_detail);
        setView();
        return view;
    }

    private void setView() {
        mText.setText(mDescreption[mIndex - 1]);
        switch (mIndex) {
            case 1:
                mEntryImg.setImageResource(R.drawable.ic_big_body_fat);
                mLine.setBackgroundResource(R.color.text_color_bmi);
                mPercentText.setText(String.format(getString(R.string.percent), mDashboard.getBody_fat() + ""));
                mYourText.setText(String.format(getString(R.string.your_s), getString(R.string.body_fat)));
                break;
            case 2:
                mEntryImg.setImageResource(R.drawable.ic_big_muscle);
                mLine.setBackgroundResource(R.color.text_color_muscle);
                mPercentText.setText(String.format(getString(R.string.percent), mDashboard.getMuscle() + ""));
                mYourText.setText(String.format(getString(R.string.your_s), getString(R.string.muscle)));
                break;
            case 3:
                mEntryImg.setImageResource(R.drawable.ic_big_water);
                mLine.setBackgroundResource(R.color.text_color_water);
                mPercentText.setText(String.format(getString(R.string.percent), mDashboard.getWater() + ""));
                mYourText.setText(String.format(getString(R.string.your_s), getString(R.string.water_s)));

                break;
            case 4:
                mEntryImg.setImageResource(R.drawable.ic_big_bone_mass);
                mLine.setBackgroundResource(R.color.text_color_bone_mass);
                mPercentText.setText(String.format(getString(R.string.bone_unit), mDashboard.getBone_mass() + ""));
                mYourText.setText(String.format(getString(R.string.your_s), getString(R.string.bone_mass)));
                break;
            case 5:
                mEntryImg.setImageResource(R.drawable.ic_big_bmr);
                mLine.setBackgroundResource(R.color.bg_select_tall_btn);
                mPercentText.setText(String.format(getString(R.string.kcal), mDashboard.getBmr() + ""));
                mYourText.setText(String.format(getString(R.string.your_s), getString(R.string.bmr)));
                break;
            case 6:
                mEntryImg.setImageResource(R.drawable.ic_big_visceral_fat);
                mLine.setBackgroundResource(R.color.text_color_visceral_fat);
                mPercentText.setText(mDashboard.getVisceral_fat() + "");
                mYourText.setText(String.format(getString(R.string.your_s), getString(R.string.visceral_fat)));
                break;

        }
    }
}
